//
//  ViewController.swift
//  RuiQue-Swift
//
//  Created by xiute on 2018/10/30.
//  Copyright © 2018 cuijin. All rights reserved.
//

import UIKit
import SliderComponent
import RQConfig


class ViewController: UIViewController{

    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupViews()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.viewModel.getNetData()
    }
    
    func setupViews() -> Void {
        let sliderView = SliderView(frame: CGRect.init(x: 0, y: 64 + 44, width: kScreenWidth, height: kScreenHeight - 64 - 44))
        self.viewModel.sliderView = sliderView
        self.view.addSubview(sliderView)
        self.view.addSubview(self.topSliderView)
    }
    
    
    lazy var viewModel: RQViewModel = {
        let viewModel = RQViewModel()
        viewModel.completeHandleData = { () in
            self.topSliderView.datasource = viewModel.keys
        }
        viewModel.context = self;
        return viewModel
    }()
    
    lazy var topSliderView: TopSliderView = {
        let topSliderView = TopSliderView(frame: CGRect.init(x: 0, y: 44, width: kScreenWidth, height: 44));
        topSliderView.selectBlock = { (index) in
            self.viewModel.didSelect(index)
        }
        topSliderView.datasource = self.viewModel.keys
        return topSliderView
    }()
}

